/**
 * by binxchen  6-26
 */

const mongoose = require('mongoose');
const config = require('./db.js');

let db = mongoose.connect(config.mongodb);
// 连接成功 
db.connection.on('connected', function() {
  console.log('Mongoose connection open to ' + config.mongodb);
});

// 连接失败
db.connection.on('error', function(err) {
  console.log('Mongoose connection error: ' + err);
});

// 断开连接
db.connection.on('disconnected', function() {
  console.log('Mongoose connection disconnected');
});

module.exports = function () {
    require('../models/user');
    require('../models/individual');
    require('../models/apiList');
    require('../models/api');
    require('../models/files');   
    return db;
}
